import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@SuppressWarnings("serial")
public class AdjustStockServlet extends HttpServlet{
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ItemHandler itemHandler = new ItemHandler();
		
		String itemID = request.getParameter("itemID");
		String adjustment = request.getParameter("adjustment");
		
		itemHandler.adjustItemStock(itemID, adjustment);
		
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		out.println("<html><h1>" + "Item stock adjustet for item: " + itemID + " by  " + adjustment +"</h1></html>");
		
		response.setHeader("Refresh", "2");
//		response.setHeader("Location", "index.jsp");
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
		response.setHeader("Location", "adminPage.jsp");
	}
}